﻿using AutoMapper;
using Pay.DTO;
using Pay.Data;
using Pay.IService;
using System;
using Pay.Core;

namespace Pay.Service.AutoMapper {
	public class ShopMapper : IStartupDto {
		private IMapperConfigurationExpression _cfg;
		public ShopMapper(IMapperConfigurationExpression cfg) {
			_cfg = cfg;
		}
		public void Execute() {
			Create();
		}
		protected virtual void Create() {
			_cfg.CreateMap<Shop, shop_dto>()
				.ForMember(dest => dest.id, src => src.MapFrom(c => c.Id))
				.ForMember(dest => dest.logo, src => src.MapFrom(c => c.Logo))
				.ForMember(dest => dest.merchant_id, src => src.MapFrom(c => c.MerchantId))
				.ForMember(dest => dest.shop_name, src => src.MapFrom(c => c.ShopName))
				.ForMember(dest => dest.banner, src => src.MapFrom(c => c.Banner))
				.ForMember(dest => dest.disabled, src => src.MapFrom(c => c.Disabled))
				.ForMember(dest => dest.region_name, src => src.MapFrom(c => c.RegionName))
				.ForMember(dest => dest.area_id, src => src.MapFrom(c => c.RegionId))
				.ForMember(dest => dest.seller_phone, src => src.MapFrom(c => c.SellerPhone))
				.ForMember(dest => dest.address, src => src.MapFrom(c => c.Address))
				.ForMember(dest => dest.create_date, src => src.MapFrom(c => c.CreateDate.ToDateTime()))
				.ForMember(dest => dest.banner, src => src.MapFrom(c => c.Banner))
				.ForMember(dest => dest.description, src => src.MapFrom(c => c.Description))
				.ForMember(dest => dest.in_rate, src => src.MapFrom(c => c.InRate))
				.ForMember(dest => dest.out_rate, src => src.MapFrom(c => c.OutRate))
				.ForMember(dest => dest.is_int, src => src.MapFrom(c => c.IsInt))
				.ForMember(dest => dest.setting, src => src.MapFrom(c => c.Setting.ToObject<shop_setting>()));
		}
	}
}
